package xesj.test;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.chainsaw.Main;


public class SqlConnection {  
   
	    private static final String URL="jdbc:mysql://localhost:3306/xesj?";  
	    private static final String NAME="xesj";
	    private static final String PASSWORD="289106";  
	      
	    public static void TheSqlConnection()  
	    {  
	        //1.加载驱动  
	        try {  
	            Class.forName("com.mysql.jdbc.Driver");  
	        } catch (ClassNotFoundException e) {  
	            System.out.println("未能成功加载驱动程序，请检查是否导入驱动程序！");                         
	            e.printStackTrace();  
	        }  
	        Connection conn = null;  
	        try {  
	            conn = (Connection) DriverManager.getConnection(URL, NAME, PASSWORD);  
	                System.out.println("获取数据库连接成功！");  
	        } catch (SQLException e) {  
	            System.out.println("获取数据库连接失败！");  
	                 
	            e.printStackTrace();  
	        }  
	               //数据库打开后就要关闭  
	        if(conn!=null)  
	        {  
	            try {  
	                conn.close();  
	            } catch (SQLException e) {  
	               
	                e.printStackTrace();  
	                conn=null;  
	            }  
	        }  
	        
	        
	        
	    }  
	    
	    public static void main(String[] args) {
	    	TheSqlConnection();
	    			
		}
	    
	}  